﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YAMP;

namespace SayisalAnaliz.Library
{
    public static class TrapezYontemi
    {
        public static double Uygula(double altDeger,double ustDeger,int parca,string fonksiyon)
        {
            fonksiyon = fonksiyon.Replace(',', '.');
            double h = (ustDeger - altDeger) / parca;

            double f0 = ((ScalarValue)Parser.Parse(fonksiyon).Execute(new { x = altDeger })).Value;
            double fn = ((ScalarValue)Parser.Parse(fonksiyon).Execute(new { x = ustDeger })).Value;
            double fi =0;
            for (int i = 1; i < parca; i++)
            {
                fi += ((ScalarValue)Parser.Parse(fonksiyon).Execute(new { x = altDeger + h * i })).Value;
            }
            double sonuc = h * ((f0 + fn) / 2 + fi);
            return sonuc;  
        
        }
    }
}
